
import ChartForm, { FormState } from "./ChartForm";
import { ChartFormItemContext } from "./ChartFormItem";
import { IChartFormItem, IMateData } from "./ChartItemType";
import { EPieChartSubType, ESubAxisChartType } from "../core/ChartType"
export default class ChartFormContext {
    private chartForm!: ChartForm;
    private watchFn!: () => void;
    private renderFn!: (formConfig: { [key: string]: IChartFormItem }) => void;
    constructor(chartForm?: ChartForm) {
        if (chartForm) {
            this.chartForm = chartForm;
        }
    }
    setChartForm(chartForm: ChartForm) {
        this.chartForm = chartForm;
        if (this.renderFn) {
            chartForm.renderFunc = this.renderFn;
            this.renderFn(chartForm.getCommonFormRenderConfig());
        }
    }
    setChartSubType(subType: number) {
        this.chartForm.setSubChartType(subType);
    }
    setFormState(name: string, data: any) {
        this.chartForm.setFormState(name, data);
    }

    watch(watchFn: (configs: IterableIterator<[string, FormState<any>]>) => void) {
        this.chartForm.setComputeWatcher(watchFn);
    }

    renderForm(renderFn: (formConfig: { [key: string]: IChartFormItem }) => void, mateData: Array<IMateData>) {
        this.renderFn = renderFn;
        if (this.chartForm) {
            this.chartForm.renderFunc = this.renderFn;
            this.renderFn(this.chartForm.getCommonFormRenderConfig());
        }
    }
}